import functools
class Solution(object):
    def possiblyEquals(self, s1, s2):
        n1 = len(s1)
        n2 = len(s2)
        @functools.cache
        def dfs(left1, left2, i, j):
            if left1 == 0 and left2 == 0:
                if i == n1:
                    if j == n2:
                        return True
                    else:
                        return False
                else:
                    if j == n2:
                        return False
                    else:
                        st1 = []
                        if '1' <= s1[i] <= '9':
                            next_i = i
                            while next_i < n1 and '1' <= s1[next_i] <= '9':
                                st1.append([0, int(s1[i: next_i + 1]), next_i + 1])
                                next_i += 1
                        else:
                            st1.append([1, s1[i], i + 1])
                        st2 = []
                        if '1' <= s2[j] <= '9':
                            next_j = j
                            while next_j < n2 and '1' <= s2[next_j] <= '9':
                                st2.append([0, int(s2[j: next_j + 1]), next_j + 1])
                                next_j += 1
                        else:
                            st2.append([1, s2[j], j + 1])
                        for p1 in st1:
                            for p2 in st2:
                                if p1[0] == 0:
                                    if p2[0] == 0:
                                        if p1[1] >= p2[1]:
                                            if dfs(p1[1] - p2[1], 0, p1[2], p2[2]):
                                                return True
                                        else:
                                            if dfs(0, p2[1] - p1[1], p1[2], p2[2]):
                                                return True
                                    else:
                                        if dfs(p1[1] - 1, 0, p1[2], p2[2]):
                                            return True
                                else:
                                    if p2[0] == 0:
                                        if dfs(0, p2[1] - 1, p1[2], p2[2]):
                                            return True
                                    else:
                                        if p1[1] == p2[1] and dfs(0, 0, p1[2], p2[2]):
                                            return True
                        return False
            else:
                if left1 == 0:
                    if i == n1:
                        return False
                    else:
                        st1 = []
                        if '1' <= s1[i] <= '9':
                            next_i = i
                            while next_i < n1 and '1' <= s1[next_i] <= '9':
                                st1.append([0, int(s1[i: next_i + 1]), next_i + 1])
                                next_i += 1
                        else:
                            st1.append([1, s1[i], i + 1])
                        for p1 in st1:
                            if p1[0] == 1:
                                if dfs(0, left2 - 1, p1[2], j):
                                    return True
                            else:
                                if p1[1] >= left2:
                                    if dfs(p1[1] - left2, 0, p1[2], j):
                                        return True
                                else:
                                    if dfs(0, left2 - p1[1], p1[2], j):
                                        return True
                        return False
                else:
                    if left2 == 0:
                        if j == n2:
                            return False
                        else:
                            st2 = []
                            if '1' <= s2[j] <= '9':
                                next_j = j
                                while next_j < n2 and '1' <= s2[next_j] <= '9':
                                    st2.append([0, int(s2[j: next_j + 1]), next_j + 1])
                                    next_j += 1
                            else:
                                st2.append([1, s2[j], j + 1])
                            for p2 in st2:
                                if p2[0] == 1:
                                    if dfs(left1 - 1, 0, i, p2[2]):
                                        return True
                                else:
                                    if p2[1] >= left1:
                                        if dfs(0, p2[1] - left1, i, p2[2]):
                                            return True
                                    else:
                                        if dfs(left1 - p2[1], 0, i, p2[2]):
                                            return True
                            return False
        return dfs(0,0,0,0)




data = Solution()
# s1 = "internationalization"
# s2 = "i18n"
# print(data.possiblyEquals(s1, s2))
s1 = "l123e"
s2 = "44"
print(data.possiblyEquals(s1, s2))